<template>
	<view>
		<uni-search-bar placeholder="请输入关键词搜索" class="uni-searchbar" :radius="100" cancelButton="none" @confirm="search"
			@clear="clearKeywords"></uni-search-bar>
		<view class="container">
			<!-- <view class="click-title">
				<text :class="panelStatus[0].visible?'wz':'nr'" @click.stop="courseADC">所有课程</text>
			</view -->>
			<view class="click-title">
				<text :class="panelStatus[1].visible?'wz':'nr'" @click.stop="clickASC">申请中的课程</text>
			</view>
			<view class="click-title">
				<text :class="panelStatus[0].visible?'wz':'nr'" @click.stop="courseAll">学生加入的课程</text>
			</view>
			<view v-if="isLogin" v-for="(course,index) in courses" :key="course.id" class="head-container" @click.stop="clickShowCourse(course)">
				<image :src="course.cover" mode="aspectFill" class="img"></image>
				<text class="head-name">{{course.desc}}</text
				<text class="head-nick">{{course.teacherName}}教师</text>
				<text class="head-disc">{{nick+"学生"}}</text>
				
				<text class="head-Chapter">共{{course.status}}章</text>
				<text class="head-number">共{{course.status}}人</text>
				<text v-if="course.open == true" class="head-open"></text>
				<text v-if="course.open == true" class="open-text">✔</text>
			</view>
			<dialog-shell ref="shell" title="课程详情">
				<text style="padding-left:15rpx ;padding-top: 15rpx;">{{courseDesc}}</text>
			</dialog-shell>
		
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				isLogin: false,
				courses: [],
				nick: '',
				courseDesc: "",
				searching: false,
				goSearch: false,
				panelStatus: [{
						visible: true
					}, {
						visible: false
					},
					{
						visible: false
					},
					{
						visible: false
					},
					{
						visible: false
					},
				],
			}
		},
		onLoad() {
			this.courseAll()
		},
		mounted() {
			this.isLogin = app.globalData.token.length > 0
			this.nick = app.globalData.nickName
			if (!this.isLogin) {
				delta = 2
				this.$refs.login.show()
			}
		},
		onPullDownRefresh() {
			this.courses = [],
				console.log("执行了下拉刷新")
			
			this.courseAll()
			uni.stopPullDownRefresh()
		},
		methods: {
			
			clickASC() {
				let url = this.$params.host + this.$params.Student_apply_course
				let data = {
					token: app.globalData.token,
					id: app.globalData.uid
				}
				this.$request.glyAllget(url, data, res => {
					console.log(res)
					res.data.forEach(b => {
						if (!b.cover.startsWith('http')) {
							b.cover = this.$params.host + b.cover
						}
					})
					this.courses = res.data
				});
			},
			courseAll() {
				let url = this.$params.host + this.$params.student_course
				let data = {
					token: app.globalData.token,
					id: app.globalData.uid
				}
				this.$request.glyAllget(url, data, res => {
					console.log(res)
					res.data.forEach(b => {
						if (!b.cover.startsWith('http')) {
							b.cover = this.$params.host + b.cover
						}
					})
					this.courses = res.data
				});
			},
			courseADC() {
				let url = this.$params.host + this.$params.teacher_course
				let data = {
					token: app.globalData.token,
					id: app.globalData.uid
				}
				this.$request.glyAllget(url, data, res => {
					console.log(res)
					res.data.forEach(b => {
						if (!b.cover.startsWith('http')) {
							b.cover = this.$params.host + b.cover
						}
					})
					this.courses = res.data
				});
			},
			clickShowCourse(course) {
				this.courseDesc = "内容:" + course.desc 
				this.$refs.shell.showDialog()
				// this.$refs.login.show()
			},
			clearKeywords() {
				this.searching = false
				this.users = []
				page = 0
				this.courseAll()
			
			},
			clearSearch() {
				//清空搜索框
				this.goSearch = false
				this.users = []
				page = 0
				this.getadminUser()
			},
			search(e) {
				let kw = e.value
				if (kw.trim().length == 0) {
					return
				}
				this.goSearch = true
				this.users = []
				this.count = -1
				let url = this.$params.host + this.$params.action_search + kw
				let data = {
					token: app.globalData.token
				}
				this.$request.get(url, data, res => {
					this.users = res.data.data
				})
			},
			clickSC() {
				uni.navigateTo({
					url: '../student/Scourse',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
		}
	}
</script>

<style>
	@import url("Scourse.css");
</style>
